home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7509 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: sfluhrer@ix.netcom.com(Scott Fluhrer)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to get a random strin
  5. Date: 27 Feb 1996 04:34:53 GMT
  6. Organization: Netcom
  7. Message-ID: <4gu1ld$nis@ixnews3.ix.netcom.com>
  8. References: <4g19id$p7n@gail.ripco.com> <Dn5E0J.GKL@thinkage.on.ca> <4gqir9$d5r@airdmhor.gen.nz>
  9. NNTP-Posting-Host: ix-clv2-22.ix.netcom.com
  10. X-NETCOM-Date: Mon Feb 26  8:34:54 PM PST 1996
  11.  
  12. In <4gqir9$d5r@airdmhor.gen.nz> gumboot@airdmhor.gen.nz (Simon Hosie)
  13. writes: 
  14. [Perfectly correct advise about time() returning a time_t, which might
  15. be a float, and so you have to #include <time.h> to tell the compiler
  16. that]
  17. >
  18. >  I don't follow that.. if time returns a float then won't the result
  19. >be cast and truncated to an int?
  20. Well, if the compiler doesn't know that time returns a float, then it
  21. won't know to insert the code to do the cast.  So, you may get the bit
  22. pattern of the float, interpretted as an int, or, as the previous
  23. poster stated, you might get an integer register which happends to be 
  24. always the same value when time() returns.
  25. >
  26. >Is the following legal, by the way?
  27. >
  28. >    char Temp[sizeof(time_t) + sizeof(unsigned)];
  29. >
  30. >    time((time_t *)Temp);
  31. >    srand(*(unsigned *)Temp);
  32. Absolutely not: for one, the Temp array needn't be alignmented properly
  33. to hold either a time_t or an unsigned int.
  34.  
  35. poncho
  36.